package com.dyxy.tms.model;

import java.util.List;
import java.util.Map;

import com.dyxy.tms.App;
import com.dyxy.tms.R;
import com.dyxy.tms.views.CircleImageView;
import com.squareup.picasso.Picasso;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class IconBaseAdapter extends BaseAdapter {
	LayoutInflater mInflater;
	List<Map<String, Object>> list ;
	Map<String, Object> map;

	public IconBaseAdapter(Activity activity, List<Map<String, Object>> list) {
		// TODO Auto-generated constructor stub
		mInflater = LayoutInflater.from(activity);
		this.list = list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@SuppressLint("InflateParams")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		View view = null ;
		// TODO Auto-generated method stub
		if (view == null) {
			view = mInflater.inflate(R.layout.item_index_gridview,null);
			viewHolder = new ViewHolder(view);
			view.setTag(viewHolder);
		}else if (view != null) {
			view = convertView;
			viewHolder = (ViewHolder) view.getTag();
		}
		
		map = list.get(position);
		
		Picasso.with(App.getInstance().getApplicationContext()).
			load((String)map.get("img")).into(viewHolder.imgV);
		String title = (String)map.get("title");
		viewHolder.tv.setText(title);
//		viewHolder.tv.setText(map.get("title").toString());
		return view;
	}

	class ViewHolder {
		private CircleImageView imgV;
		private TextView tv;

		public ViewHolder(View v) {
			imgV = (CircleImageView) v.findViewById(R.id.item_index_gridview_imgV);
			tv = (TextView) v.findViewById(R.id.item_index_gridview_tv);
			// TODO Auto-generated constructor stub
		}
	}

}
